/**  
 * 第一题：函数柯里化-----剩余参数持续调用
 * 对比 5-29函数柯里化的例子
 * 实现以下需求的函数
 * const foo = function(...ags) {}
 * 
 * foo(1, 2, 3) === 6 // true
 * foo(1)(2, 3) === 6 // true
 * foo(1)(2)(3)(4) === 10 // true 
 */

function foo(...ags) {
    let sum1 = ags.reduce((pre, nxt) => {
        return pre + nxt;
    }, 0);
    function innerFn(...ags2) {
        const sum2 = ags2.reduce((pre, nxy) => {
            return pre + nxy;
        }, 0);
        return foo(sum1 + sum2);
    };
    innerFn.toString = () => {
        return sum1;
    }
    return innerFn;
}

let res2 = foo(1)(2, 3);
let res1 = foo(1, 2, 3);
let res3 = foo(1)(2)(3)(4)
console.log('res2:', res2 === 6);
console.log('res1:', res1 === 6);
console.log('res3:', res3 === 10);




